// pages/foodcontent/foodcontent.js
// let config = require('../../utils/config.js');
let app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    host: app.globalData.host
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let id = options.id;
    this.requestData(id)
  },

  /**
   * 
   */
  requestData: function(id) {
    // 这里注意this的指向
    let that = this;

    wx.request({
      url: that.host + 'api/productcontent?id=' + id,
      data: '',
      header: {
        'content-type': 'application/json'
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        // console.log(res);

        res.data.result[0].img_url = res.data.result[0].img_url.replace(/\\/g, '/');

        // 这里注意this的指向
        that.setData({
          list: res.data.result[0]
        })
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  }

})